package test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class User {
    //@Pattern(regexp = "^[^A-Za-z0-9]+$")
    private String username;

    public User(String username) {
        this.username = username;
    }

    public String getUsername() {
        return username;
    }

    public static void main(String[] args) {
        String REGEX = "^(平原|山地|丘陵|高原|戈壁荒漠|濒海|海岛滩涂)(,(平原|山地|丘陵|高原|戈壁荒漠|濒海|海岛滩涂))*[,]?$";
        User user1 = new User("濒海,丘陵,平原,海岛滩涂");
        //Pattern compile = Pattern.compile("[(平原)|(丘陵)|(山地)|(高原)|(戈壁荒漠)|(濒海)|(海岛滩涂)]");
        Pattern compile = Pattern.compile(REGEX);

        System.out.println(compile.matcher(user1.getUsername()).matches());
        Matcher matcher = compile.matcher(user1.getUsername());
        while (matcher.find()) {
            System.out.println(matcher.group());
        }


        if (user1.getUsername().matches(REGEX)) {
            System.out.println("====不合法====");
        } else {
            System.out.println("合法");
        }
    }
}